cmake_minimum_required(VERSION 3.10.0)
project(afl)

# BIN_PATH    = $(PREFIX)/bin
# HELPER_PATH = $(PREFIX)/lib/afl
# DOC_PATH    = $(PREFIX)/share/doc/afl
# set(CMAKE_CXX_STANDARD 11)

# 设置输入和输出
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# file(GLOB DIR_SRCS "afl-*.c")

# 设置公共头文件
set(BIN_PATH ${CMAKE_BINARY_DIR}/bin)
set(HELPER_PATH ${CMAKE_BINARY_DIR}/lib/afl)
set(DOC_PATH ${CMAKE_BINARY_DIR}/share/doc/afl)

set(COMM_HDR
    alloc-inl.h
    config.h
    debug.h
    types.h
)
# 设置shell脚本
set(SH_PROGS  
    afl-plot
    afl-cmin
    afl-whatsup
)

set(TEST_CC
    afl-gcc
)

add_compile_options(-O3 -funroll-loops)
add_compile_options(-Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign)
add_compile_options(-DAFL_PATH="${HELPER_PATH}" -DDOC_PATH="${DOC_PATH}" -DBIN_PATH="${BIN_PATH}")
# add_compile_options(-ldl)

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -funroll-loops -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign")

# include(CTest)
# enable_testing()

# 设置所有编译的文件
set(PROGS afl-gcc afl-fuzz afl-showmap afl-tmin afl-gotcpu afl-analyze)
foreach(f ${PROGS})
    # message(${f})
    # add_executable(${f} ${f}.c ${COMM_HDR})
    add_library(${f} ${f}.c ${COMM_HDR})

    # add_library(${f} Shared ${f}.c ${COMM_HDR})
    # message(${f} ${f}.c ${COMM_HDR})
    # add_library(${f} ${f}.c ${COMM_HDR})
endforeach()
target_link_libraries(afl-fuzz pthread dl)
# 单独配置afl-as
# add_executable(afl-as afl-as.c afl-as.h ${COMM_HDR})
add_library(afl-as afl-as.c afl-as.h ${COMM_HDR})


# add_executable(afl main.cpp)

# set(CPACK_PROJECT_NAME ${PROJECT_NAME})
# set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
# include(CPack)


# target_include_directories(${PROJECT_SOURCE_DIR})